package org.springblade.modules.admin.controller;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import org.springblade.core.secure.utils.AuthUtil;
import org.springblade.core.tool.api.R;
import org.springblade.modules.admin.entity.ElevatorAudit;
import org.springblade.modules.admin.enums.ElevatorAuditEnum;
import org.springblade.modules.admin.service.ElevatorAuditService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Date 9:00 2021/8/25
 * @Description {
 *   电梯年检信息接口
 * }
 * @Author lsay
 **/
@RestController
@RequestMapping("/elevator/audit")
public class ElevatorAuditController {

	@Autowired
	private ElevatorAuditService elevatorAuditService;

//	@Autowired
//	private DelayedSend delayedSend;

	@GetMapping()
	public R<ElevatorAudit> getElevatorAudit(Long elevatorId){
		return R.data(elevatorAuditService.getOne(Wrappers.<ElevatorAudit>lambdaQuery().eq(ElevatorAudit::getElevatorId,elevatorId)));
	}

	@PostMapping("/updateElevatorAudit")
	public R<Boolean> updateElevatorAudit(@RequestBody ElevatorAudit elevatorAudit){
		return R.data(elevatorAuditService.updateElevatorAudit(elevatorAudit));
	}

	/**
	 * 发送延迟消息
	 * @param privateNum 电梯编码
	 * @return
	 */
	@GetMapping("delayed_send")
	public R<String> delayedSend(String privateNum) {
		System.out.println(privateNum);

		//发送延时队列消息(当前时间毫秒值+需要延迟的毫秒值)
		long date = System.currentTimeMillis() + 10000;
		JSONObject jsonObject = new JSONObject();
		jsonObject.put("tenantId", AuthUtil.getTenantId());
		jsonObject.put("privateNum","10000220000033000002");
		jsonObject.put("checkType", ElevatorAuditEnum.AUDIT.getCode());
		jsonObject.put("sendTime","2021-01-01");
//		delayedSend.sendDelayed(date, JSONObject.toJSONString(jsonObject));

		return R.data(privateNum);
	}

	/**
	 * 同步电梯年检时间
	 * @return
	 */
	@PostMapping("/batchUpdateElevatorAuditTime")
	public R batchUpdateElevatorAuditTime() {
		return R.data(elevatorAuditService.batchUpdateElevatorAuditTime());
	}

}
